<?php

// 抽奖商品中奖列表

namespace app\console\controller;

use think\Request;
use think\Controller;
use app\client\model\Express as ExpressModel;
use app\console\model\DrawWinner as DrawWinnerModel;
use think\Url;

class DrawGoods extends Controller
{
    // 精品兑换
    public function index()
    {
        // 实例化
        $model = new DrawWinnerModel();

        // 筛选
        $con = [
            'id'    => 1,
            'level' => ['gt', 3]
        ];

        $data = $model->relation('Member')->where($con)->paginate(10);


        return $this->fetch('', [
            'mate_title' => '兑奖信息列表',
            'data'       => $data,
        ]);
    }


    public function update()
    {
        // 获取参数
        $order_id = Request::instance()->param('order_id');

        // 实例化
        $model = new DrawWinnerModel();

        if (Request::instance()->isPost()) {
            // 获取数据
            $data = Request::instance()->param();

            // 操作数据
            $operation = $model->allowField(true)->save($data,['id'=>$data['id']]);

            if ($operation) {
                win('操作成功',Url::build('DrawGoods/index'));
            }
            fail('操作成功');


        }


        // 获取数据
        $item = $model->relation('Member')->where('id', $order_id)->find();

        $express_list = ExpressModel::all();


        return $this->fetch('', [
            'mate_title' => '编辑订单',
            'item'       => $item,
            'express_list' => $express_list,
        ]);
    }
}